#include "resource/loader.h"
#include "core/File.h"

using namespace kraw;

AssetLoader::AssetLoader() :
resource(NULL),
buffer(NULL),
bufferSize(0),
isLoaded(false)
{
}

AssetLoader::~AssetLoader()
{
}

std::string AssetLoader::getAssetName()
{
	return assetName;
}

bool AssetLoader::loadBuffer()
{
	//TODO- check for url

	File file(assetName);
	if (file.open()) {
		bufferSize = file.getSize();
		buffer = new unsigned char[bufferSize];
		file.read(buffer, bufferSize);
		file.close();
		return true;
	}

	return false;
}

void AssetLoader::unloadBuffer()
{
	if (buffer) {
		delete[] buffer;
		buffer = NULL;
		bufferSize = 0;
	}
}
